import { Controller } from "egg";
import { mapKeys, camelCase } from "lodash";

export default class VersionController extends Controller {
  // 版本是二级页面，属于应用管理的子页面
  public async list(ctx) {
    // const { page } = ctx.request.body;
    const page = 1;
    // 参数校验失败自动返回422状态
    // ctx.validate(appSearchParamRule);
    // ctx.response.status = 404;
    const { count, rows: list } = await ctx.model.Version.findAndCountAll({
      offset: (page - 1) * 10,
      limit: 10
    });
    ctx.logger.info({ count, list });
    ctx.body = {
      success: true,
      data: {
        count,
        list: list.map(r =>
          mapKeys(r.get(), (_v, k) => {
            return camelCase(k);
          })
        )
      }
    };
  }

  public async findAll(ctx) {
    const list = await ctx.model.Version.findAll();
    ctx.body = {
      success: true,
        list: list.map(r =>
            mapKeys(r.get(), (_v, k) => {
                return camelCase(k);
            })
        )
    };
  }

  public async create(ctx) {
    ctx.body = {};
  }

  public async update(ctx) {
    ctx.body = {};
  }
}
